package com.example.makerspace;;
import com.alibaba.excel.EasyExcel;
import com.example.makerspace.vo.ProductVO;
import com.google.code.chatterbotapi.ChatterBot;
import com.google.code.chatterbotapi.ChatterBotFactory;
import com.google.code.chatterbotapi.ChatterBotSession;
import com.google.code.chatterbotapi.ChatterBotType;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

import static com.example.makerspace.utils.ExcelUtil.readExcel;

public class test01 {
    public static void main(String[] args) throws IOException {

        String url="https://nism.ytcata.com:3005/application/showProducts?aoaa4qRnEII2V8dhttps=Kn2ohWb8GkRW7qDW_aUwTCqbUBE4BHMNmnbwa3Wsm4DRf1Kx_7dA4bc3b82e8shzrDOFiLox.jTYIMABwZyBME_VN7lT9IeqkCcpk7vcZKDeZ";
        // 这里假设保存到本地，获取保存路径
        String filePath = "C:\\Users\\Lenovo\\Desktop\\产品测试.xlsx";
        List<Object> data = new ArrayList<Object>();

        Document document = Jsoup.parse(new URL(url), 30000);
        Elements elementsByClass = document.getElementsByClass("active");
        Element el = elementsByClass.first();
        String text = el.text();
         data.add(text);
        Elements elementsByClas1 = document.getElementsByClass("tit");
        for(int i=0;i<elementsByClas1.size();i++){
           data.add(elementsByClas1.get(i).text());
            System.out.println(elementsByClas1.get(i).text());
        }
        Elements elementsByClas2 = document.getElementsByClass("explain");
        for(int i=0;i<elementsByClas2.size();i++){
            data.add(elementsByClas2.get(i).text());
            System.out.println(elementsByClas2.get(i).text());
        }
        write(filePath,data, ProductVO.class);
    }

    public  static  void  write(String filePath, List<Object> data, Class<?> clazz){
        // 写入数据到 Excel 文件
        EasyExcel.write(filePath, clazz).sheet().doWrite(data);
    }


}
